<template>
	<!-- 申请工具清单 -->
	<div id="toolInfo">
		<div class="gcontent" v-if="toolInfo.toolList.length > 0">
			<Form :label-width="labelWidth" label-position="left" class="form form_left ">
				<div v-show="ifedit && tempTool != undefined && tempTool.length > 0" v-for="(item,toolKey) in tempTool" :key="toolKey">
					<CheckboxGroup v-model="applyinfo.tools.checkList">
						<Row style="padding-top: 15px">
							<Col span="4">
							<Checkbox class="font_seize" v-bind:label="item.toolId" :disabled="ifedit">
								{{item.toolName}}
							</Checkbox>
							<Tooltip :content="item.des === undefined || item.des === null ||  item.des === '' ? '暂无信息':item.des" max-width="400"
							 placement="right" :transfer="true" style="white-space: normal;position: absolute;width: 20px;">
								<Icon type="md-help-circle" />
							</Tooltip>
							</Col>
							<Col span="10" v-if="applyinfo.tools.checkList.indexOf(item.toolId) != -1 && item.needResources != null && item.needResources.length > 0">
							<RadioGroup v-model="toolInfo.toolList[toolKey].default" v-if="!ifedit">
								<Radio :label=0>默认</Radio>
								<Radio :label=1>自定义</Radio>
							</RadioGroup>
							</Col>
						</Row>
					</CheckboxGroup>
					<Row style="padding-top: 8px" v-if="applyinfo.tools.checkList.indexOf(item.toolId) != -1 && item.needResources != null && item.needResources.length > 0">
						<Col span="21" style="width: 97%;">
						<resourceTable :ifedit="ifedit" :type="'tool'" :isEditTool="toolInfo.toolList[toolKey].default == 0 ? false : true"
						 v-model="item.needResources" :columnsList="toolInfo.toolColumns"></resourceTable>
						</Col>
					</Row>
				</div>
				<div v-show="(isEdit != 1 && ifedit)|| !ifedit &&(toolInfo.toolList.length > 0 )" v-for="(item,toolIndex) in toolInfo.toolList">
					<CheckboxGroup v-model="applyinfo.tools.checkList">
						<Row style="padding-top: 15px">
							<Col span="12">
							<Checkbox class="font_seize" v-bind:label="item.toolId" :disabled="ifedit">
								{{item.toolName}}
							</Checkbox>
							<Tooltip :content="item.des === undefined || item.des === null ||  item.des === '' ? '暂无信息':item.des" max-width="400"
							 placement="right" :transfer="true" style="white-space: normal;">
								<Icon type="md-help-circle" />
							</Tooltip>
							</Col>

						</Row>
						<Row style="padding-top: 8px;padding-left:8px">
							<Col span="10" v-if="applyinfo.tools.checkList.indexOf(item.toolId) != -1 && item.needResources != null && item.needResources.length > 0">
							<RadioGroup v-model="toolInfo.toolList[toolIndex].default" v-if="!ifedit">
								<Radio :label=0>默认</Radio>
								<Radio :label=1>自定义</Radio>
							</RadioGroup>
							</Col>
						</Row>
					</CheckboxGroup>
					<Row style="padding-top: 8px;padding-left:8px" v-if="applyinfo.tools.checkList.indexOf(item.toolId) != -1 && item.needResources != null && item.needResources.length > 0">
						<Col  style="width: 97%;">
						<resourceTable :ifedit="ifedit" :type="'tool'" :isEditTool="toolInfo.toolList[toolIndex].default == 0 ? false : true"
						 v-model="item.needResources" :columnsList="toolInfo.toolColumns"></resourceTable>
						</Col>
					</Row>
				</div>
			</Form>
		</div>
		<template v-else>
			<div class="gcontent" style="text-align:center">
				<span style="font-size: 13px;margin-left: 15px;color:#bbb; ">暂无申请工具</span>
			</div>
		</template>
	</div>
</template>
<script>
	import ajax from "../../../ajax_util"
	import Axios from 'axios'
	import resourceTable from "../../../base/tables"

	export default {
		name: "apply",
		components: {
			resourceTable
		},
		data() {

			return {
				dataInfoEdit: 0,
				readonly: true, //是否只读
				labelWidth: 140,

				//工具相关基础信息
				toolInfo: this.Ptool,
				//数据相关基础信息
				applyinfo: this.Papply
			}
		},
		created: function() {},
		mounted: function() {},
		computed: {},
		methods: {
			clicks(index) {
				if (this.clickindex === index) {
					if (this.click) {
						this.click = false
					} else {
						this.click = true
					}
				} else {
					if (!this.click) {
						this.click = true
					}
				}
				this.clickindex = index;
			},
			// 选择工具
			chackeTool(id) {
				if (this.applyinfo.tools.checkList.indexOf(id) == -1) {
					this.applyinfo.tools.checkList.push(id)
				} else(
					this.applyinfo.tools.checkList.splice(this.applyinfo.tools.checkList.indexOf(id), 1)
				)
			},
			// 处理工具信息
			getTool() {
				var toolCheck = this.applyinfo.tools.checkList
				var temp = []
				toolCheck.forEach(item => {
					this.toolInfo.toolList.some(tool => {
						if (item === tool.toolId) {
							temp.push(tool)
							return true
						}
					})
				})
				console.log("tool------>", temp)
				return temp
			},
			//格式化日期
			formatDate(value) {
				var date = new Date(value * 1000);
				var year = date.getFullYear();
				var month = this.padDate(date.getMonth() + 1);
				var day = this.padDate(date.getDate());
				var hours = this.padDate(date.getHours());
				var minutes = this.padDate(date.getMinutes());
				var seconds = this.padDate(date.getSeconds());
				return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds;
			},
			padDate(value) {
				return value < 10 ? '0' + value : value;
			},
		},
		props: {
			isEdit: {},
			ifedit: {},
			Papply: {},
			Ptool: {},
			tempTool: {}
		},


	}
</script>
